import storage from '@/utils/common/storage'
const state = {
  user: ''
}
const getters = {
  user () {
    return state.user
  }
}
const mutations = {
  loginAndSave (state, user) {
    state.user = user
    storage.set('user', JSON.stringify(user))
  },
  logoutAndRemove (state) {
    state.user = ''
    storage.remove('user')
  }
}
const actions = {
  saveUserInfo (exec, user) {
    exec.commit('loginAndSave', user)
  },
  // 用户注销
  removeUserInfo (exec) {
    exec.commit('logoutAndRemove')
  }
}
const login = {
  state,
  getters,
  mutations,
  actions
}
export default login
